<?php


namespace app\api\controller\v14;


use app\api\controller\v2\Auth;
use app\common\model\UserPush;

class Push extends Auth
{
    public function bind()
    {
        $regid = input('regid/s', '');
        $push_type = input('push_type/d', 1);
        $onlyCode = input('only_code/s', '');
        $notice_status = input('notice_status/d', 0);
        $device_token = input('device_token/s', '');//ios设备的device_token（ios 2.6.2以上有效）

        $version = $this->headers['version'] ?? '';
        $model = $this->headers['model'] ?? '';
        $appType = $this->headers['app-type'] === 'android' ? 1 : 2; // 手机类型 1安卓 2IOS

        if (empty($regid) && empty($device_token))
        {
            return show(config('code.error'), 'regid不能为空');
        }

        if ($this->simulationLogin)
        {
            return show(config('code.success'), '绑定成功');
        }

        $data = [
            'status' => $notice_status,
            'regid' => $regid,
            'push_type' => $push_type,
            'version' => 'V' . $version,
            'model' => $model,
            'type' => $appType,
            'only_code' => $onlyCode,
            'device_token' => $device_token
        ];

        (new UserPush())->pushBind($data, (int)$this->user['id']);

        return show(config('code.success'), '绑定成功');
    }
}
